<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>搜索学校</title>
		<link rel="stylesheet" href="../libs/mui/mui.css"/>		
		<link rel="stylesheet" href="../libs/iconfont/fonts/iconfont.css"/>
		<link rel="stylesheet" type="text/css" href="../css/main.css"/>
		<style>			
			 /*头部搜索*/					
			.mui-bar.mui-bar-nav h1,.mui-bar.mui-bar-nav input {color: black;}
			.mui-bar .mui-input-row .mui-input-clear~.mui-icon-clear, .mui-bar .mui-input-row .mui-input-speech~.mui-icon-speech{top: 12px;}			 	
			.mui-content{font-size: 16px;}
			.mui-bar .mui-title{right: 50px;}
			.mui-input-row input[type=search]{background-color: white; width: 100%;margin-bottom: 0px;border-radius: 100px;}
			.mui-search .mui-placeholder{line-height: 44px;}
			.mui-bar .mui-search:before {margin-top: -22px;}		    	
		</style>
	</head>
	<body>		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">
		    	<div class="mui-input-row mui-search">
					<input type="search" id="search" class="mui-input-clear" placeholder="请输入学校名称">
				</div>
		    </h1>	
			<a class="mui-pull-right mui-icon">
				<h5 class="search_goods">搜索</h5>			
			</a>		
		</header>		
		<div class="mui-content">
			<div class="School">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<div>当前定位：<span class="store_name"></span></div>
						<!--<i class="mui-icon iconfont mui-pull-right mui-h5">&#xe632;</i>-->
					</li>
				</ul>
				<!--<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<span>非高校地区</span>						
					</li>
				</ul>-->
				<div class="verify mui-h5">搜索结果</div>
				<div class="result">
					
				</div>
				<!--<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<span>山东大学</span>						
					</li>
				</ul>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<span>北京大学</span>						
					</li>
				</ul>-->
			</div>
		</div>	
	</body> 
	<script type="text/javascript" src="../js/open.js"></script>
	<script type="text/javascript" src="../libs/mui/mui.js"></script>
	<script type="text/javascript" src="../libs/jquery/jquery.js"></script>
	<script type="text/javascript" src="../js/web_js/public.js" ></script>
	<script type="text/javascript">
		var ws = '';
		document.addEventListener('plusready',function(){
			ws = plus.webview.currentWebview();
			var store_name = plus.storage.getItem('store_name');
			$('.store_name').text(store_name);
			$('#search').keydown(function(e){
				if(e.which == 13) {
					likekey = $('#search').val();
					if(!likekey){toast('无法进行空搜索');return;}
					goods_inf(likekey)
				}
			})
			$('.search_goods').on('click',function(e){
				likekey = $('#search').val();
				if(!likekey){toast('无法进行空搜索');return;}
				goods_inf(likekey)
			})
			
		})
		function goods_inf(likekey){
			plus.nativeUI.showWaiting('搜索中...');
			$.ajax({ 
				type:"post",
				url:apiRoot + "?act=goods&op=school_search",
				data:{
					likekey:likekey
				}, 
				dataType:'json',
				success:function(data){
					plus.nativeUI.closeWaiting();
					console.log(JSON.stringify(data));
					if(data.code == 200){ 
						if(data.datas.length > 0){
							var html = ''; 
							$.each(data.datas, function(k,v) {
								html += '<ul class="mui-table-view choice" data-store_id="'+ v.store_id +'" data-store_name="'+ v.store_name +'" data-lat="'+ v.lat +'" data-lng="'+ v.lng +'">'+
											'<li class="mui-table-view-cell">'+
												'<span>'+ v.store_name +'</span>	'+				
											'</li>'+
										'</ul>';
							});
							$('.result').html(html);
							
							//选择商家
							$('.choice').unbind('click');
							$('.choice').on('click',function(){
								var _this = $(this);
								var store_id = _this.attr('data-store_id');
								var store_name = _this.attr('data-store_name');
								var lat = _this.attr('data-lat');
								var lng = _this.attr('data-lng');
//								console.log(lat+'--'+lng);return;
								if(store_id && store_name){
									toast('更改成功！');
									$('.store_name').text(store_name);
									plus.storage.setItem('store_id', store_id); //定位商家id
									plus.storage.setItem('store_name', store_name + ''); //定位商家名称
									plus.storage.setItem('lat',lat + '');
									plus.storage.setItem('lng',lng + '');
									relogin(ws.id);
								}else{
									toast('选取失败！请尝试重新连接！');
								}
							})
							
						}else{
							toast('没有搜索结果！');
						}
					}else{ 
						toast('没有搜索结果！');
					}
				},
				error:function(e){
					plus.nativeUI.closeWaiting();
					console.log(JSON.stringify(e));
					error();
				}
			});
		}
	</script>
</html>